package tableprocessor;

import com.sun.org.apache.xerces.internal.xs.StringList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Table
{
    private List<List<String>> rows;
    public Table()
    {
        rows = new ArrayList<List<String>>();
    }
    public String getData(int row , int col)
    {
        if (row <= rows.size() && col <= rows.get(row).size())
        {
            return rows.get(row).get(col);
        }
        return null;
    }
    public void setData(int row, int col, String data)
    {
        if (row < rows.size() )
        {
                rows.get(row).add(col, data);
        }
        if (row >= rows.size())
        {
            List l = new ArrayList();
            l.add(data);
            rows.add(l);
        }

    }
    public int numRows()
    {
        return rows.size();
    }
    public int getCols(int row)
    {
        return rows.get(row).size();
    }
    public void deleteCell(int row, int col)
    {
        setData(row, col,"");
    }
    public void insertData(int row,int position, String data)
    {
        rows.get(row).add(position, data);
    }
    public void deleteRow(int row)
    {
        rows.remove(row);
    }
    public void deleteColumn(int col)
    {
          for (int i = 0 ; i < rows.size(); i++)
          {
              rows.get(i).remove(col);
          }
    }
    public void insertRow(int position)
    {
        rows.add(position, new ArrayList<String>());
    }
    public void insertColumn(int position)
    {
        for (int i = 0 ; i < rows.size(); i++)
        {
            rows.get(i).add(position, "");
        }
    }
    public void addToRow(int row, String value)
    {
        rows.get(row).add(value);
    }
    public boolean isEmpty()
    {
        return rows.isEmpty();
    }
    public void print()
    {
        for (int i = 0 ; i < rows.size(); i++)
        {

             System.out.println(rows.get(i).toString());
        }
        //for (int i = 0 ; i < rows.size(); i++)
        //{
          //  for (int j = 0 ; j < rows.get(i).size(); j++)
           // {
            //
             //   System.out.print(getData(i,j));
            //}
            //System.out.println();
        //}
    }

}
